Ext.namespace("Ext.sw.component");
Ext.sw.component.Image = Ext.extend(Ext.BoxComponent, {
	constructor: function(config) {
		config = config || {};
		config.xtype = 'box';
		config.autoEl = { tag: 'img' ,html: config.text, src: config.src };
		Ext.sw.component.Image.superclass.constructor.apply(this, arguments);
		this.text = config.text;
	},
	setParams:function(config){
		if(!config.src){
			return;
		}
		if(!this.el){
			this.autoEl.src = config.src;
		}else{
			this.el.dom.src = config.src;
		}
	},
	onRender: function() {
		this.constructor.superclass.onRender.apply(this, arguments);
	}
});
Ext.reg('image', Ext.sw.component.Image);
//超链接
Ext.LinkButton = Ext.extend(Ext.BoxComponent, {
	constructor: function(config) {
		config = config || {};
		config.xtype = 'box';
		config.autoEl = { tag: 'a', target:'_blank' ,html: config.text, href: config.href };
		Ext.LinkButton.superclass.constructor.apply(this, arguments);
		this.addEvents({
			"click": true,
			"mouseover": true,
			"blur": true
		});
		this.text = config.text;
	},
	setParams:function(config){
		if(!config.html || !config.href){
			return;
		}
		if(!this.el){
			this.html = config.html;
			this.href = config.href;
			this.autoEl.html = config.html;
			this.autoEl.href = config.href;
		}else{
			this.el.dom.innerHTML = config.html;
			this.el.dom.href = config.href;
		}
	},
	onRender: function() {
		this.constructor.superclass.onRender.apply(this, arguments);
	}
});
Ext.reg('linkbutton', Ext.LinkButton);

Ext.Embed = Ext.extend(Ext.BoxComponent, {
	constructor: function(config) {
		config = config || {};
		config.xtype = 'box';
		config.autoEl = {tag:'embed',src:config.src,quality:'high',pluginspage:'http://www.macromedia.com/go/getflashplayer',
						type:'application/x-shockwave-flash',menu:'false',loop:'true',play:'true',wmode:'Opaque'};
		Ext.Embed.superclass.constructor.apply(this, arguments);
		this.addEvents({
			"show": true
		});
		this.text = config.text;
	},
	setParams:function(config){
		if(!config.src){
			return;
		}
		config.autoEl = {tag:'embed',src:config.src,quality:'high',pluginspage:'http://www.macromedia.com/go/getflashplayer',
						type:'application/x-shockwave-flash',menu:'false',loop:'true',play:'true',wmode:'Opaque'};
		if(config.width && config.height){
			config.autoEl.width=config.width;
			config.autoEl.height=config.height;
		}
		Ext.Embed.superclass.constructor.apply(this, arguments);
	},
	iframeReSize:function(width,height){
		this.setSize(width,height);
	},
	iframeAutoSize:function(){
		var height = 0;
		var width = 0;
		if(this.el.dom.contentWindow && this.el.dom.contentWindow.frameElement.scrollHeight){
			height = this.el.dom.contentWindow.frameElement.scrollHeight;
		}
		if(this.el.dom.contentWindow && this.el.dom.contentWindow.frameElement.scrollWidth){
			width = this.el.dom.contentWindow.frameElement.scrollWidth;
		}
		return {height:height,width:width}
	},
	onloadAutoSize:function(winThis){
		var curThis = this;
		var curObj = winThis;
		if(this.el && this.el.dom){
			if (!/*@cc_on!@*/0) { //if not IE
			    this.el.dom.onload = function(){
			        var obj = curThis.iframeAutoSize();
			        if(curObj){
			        	curObj.setSize(obj.width+curObj.getFrameWidth(),obj.height+curObj.getFrameHeight());
			        }
			    };
			} else {
				var curDom = this.el.dom;
			    this.el.dom.onreadystatechange = function(){
			        if (curDom.readyState == "complete"){
			            var obj = curThis.iframeAutoSize();
				        if(curObj){
				        	curObj.setSize(obj.width+curObj.getFrameWidth(),obj.height+curObj.getFrameHeight());
				        }
			        }
			    };
			}
		}
	},
	onRender: function() {
		this.constructor.superclass.onRender.apply(this, arguments);
	},
	initComponent : function(){
        Ext.Embed.superclass.initComponent.call(this);
	}
});
Ext.reg('embed', Ext.Embed);

Ext.iFrame = Ext.extend(Ext.BoxComponent, {
	constructor: function(config) {
		config = config || {};
		config.xtype = 'box';
		config.autoEl = { tag: 'iframe',src:config.src,frameborder:0};
		Ext.LinkButton.superclass.constructor.apply(this, arguments);
		this.addEvents({
			"show": true
		});
		this.text = config.text;
	},
	setParams:function(config){
		if(!config.src){
			return;
		}
		config.autoEl = { tag: 'iframe',src:config.src,frameborder:0};
		Ext.LinkButton.superclass.constructor.apply(this, arguments);
	},
	iframeReSize:function(width,height){
		this.setSize(width,height);
	},
	iframeAutoSize:function(){
		var height = 0;
		var width = 0;
		if(this.el.dom.contentWindow && this.el.dom.contentWindow.frameElement.scrollHeight){
			height = this.el.dom.contentWindow.frameElement.scrollHeight;
		}
		if(this.el.dom.contentWindow && this.el.dom.contentWindow.frameElement.scrollWidth){
			width = this.el.dom.contentWindow.frameElement.scrollWidth;
		}
		return {height:height,width:width}
	},
	onloadAutoSize:function(winThis){
		var curThis = this;
		var curObj = winThis;
		if(this.el && this.el.dom){
			if (!/*@cc_on!@*/0) { //if not IE
			    this.el.dom.onload = function(){
			        var obj = curThis.iframeAutoSize();
			        if(curObj){
			        	curObj.setSize(obj.width+curObj.getFrameWidth(),obj.height+curObj.getFrameHeight());
			        }
			    };
			} else {
				var curDom = this.el.dom;
			    this.el.dom.onreadystatechange = function(){
			        if (curDom.readyState == "complete"){
			            var obj = curThis.iframeAutoSize();
				        if(curObj){
				        	curObj.setSize(obj.width+curObj.getFrameWidth(),obj.height+curObj.getFrameHeight());
				        }
			        }
			    };
			}
		}
	},
	onRender: function() {
		this.constructor.superclass.onRender.apply(this, arguments);
	},
	initComponent : function(){
        Ext.iFrame.superclass.initComponent.call(this);
        this.on("onload")
	}
});
Ext.reg('iframe', Ext.iFrame);